package com.example.ivory.accountbook.packetActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.example.ivory.accountbook.Activity.Activity_main;
import com.example.ivory.accountbook.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 王如梦 on 2016/8/29.
 */
public class addpacketActivity extends Activity {
    private ListView listViewAddPackets;
    private Button buttonBackPackets;
    //初始化静态的add账户界面listview的值
    private static List<Map<String,Object>> listAddDate=new ArrayList<>() ;
    private AddAdapter adapterAddPacket;

    static{
        Map<String,Object> temp=new HashMap<String,Object>();
        temp.put("type","现金");
        temp.put("logo","cash");
        listAddDate.add(temp);

        temp=new HashMap<String,Object>();
        temp.put("type","储蓄卡");
        temp.put("logo","cashcard");
        listAddDate.add(temp);

        temp=new HashMap<String,Object>();
        temp.put("type","信用卡");
        temp.put("logo","creditcard");
        listAddDate.add(temp);

        temp=new HashMap<String,Object>();
        temp.put("type","网络账户");
        temp.put("logo","webaccount");
        listAddDate.add(temp);

        temp=new HashMap<String,Object>();
        temp.put("type","投资账户");
        temp.put("logo","investment");
        listAddDate.add(temp);

        temp=new HashMap<String,Object>();
        temp.put("type","应收账");
        temp.put("logo","collectaccount");
        listAddDate.add(temp);

        temp=new HashMap<String,Object>();
        temp.put("type","应付账");
        temp.put("logo","payaccount");
        listAddDate.add(temp);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addpacket);

        //绑定界面上的控件
        buttonBackPackets= (Button) findViewById(R.id.buttonBackPacket);
        listViewAddPackets= (ListView) findViewById(R.id.listviewAddPacket);

        //创建适配器和绑定
        adapterAddPacket=new AddAdapter(addpacketActivity.this,listAddDate);
        listViewAddPackets.setAdapter(adapterAddPacket);

        //创建监听事件
        listViewAddPackets.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                //获取要创建的钱包的类型
                TextView txtType= (TextView) view.findViewById(R.id.textviewPacketType);

                String message=txtType.getText().toString();

                //跳转带上数据
                Intent intent=new Intent(addpacketActivity.this,inaddActivity.class);
                intent.putExtra("type",message);
                startActivity(intent);
                finish();
                //addpacketActivity.this.finish();
            }
        });

        //监听退回按钮
        buttonBackPackets.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               finish();
            }
        });
    }

}
